using System;

namespace Flaschengeist.Processes
{
	public class CalculateNote
	{
	    private float maxFillLevel;
	    private string[] scale;
		
		public void Inject(float maxFillLevel, string[] scale)
		{		       
			this.maxFillLevel = maxFillLevel;
	        this.scale = scale;		
		}
		
		public void Process(float newFillLevel)
		{	
	        var interval = maxFillLevel / scale.Length;
	        var posNewNote = 0;
	
	        if (newFillLevel % interval == 0)
	            posNewNote = (int)(newFillLevel / interval);
	        else
	            posNewNote = (int)(newFillLevel / interval) + 1;
	
			if (posNewNote == 0)
				Completed(scale[0]);
			else
				Completed(scale[posNewNote - 1]);
		}
		
		public event Action<string> Completed;
	}
}